package com.ssps.back.platform.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssps.back.platform.service.ComplaintService;
import com.ssps.entity.Complaint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author li
 * @time 2020/07/23 20:26:46
 */

@Controller
@RequestMapping("complaint")
public class ComplaintController {

    @Autowired
    ComplaintService complaintService;

    @RequestMapping("complaintList")
    public String complaintList(){
        return "complaint/complaintList";
    }


    @ResponseBody
    @RequestMapping("findAll")
    public Map<String,Object> complaintFindAll(@RequestParam(name = "pageNum",defaultValue = "1") Integer pageNum, @RequestParam(name = "pageSize",defaultValue = "5") Integer pageSize ,String status,String compluser, String responuser){
        Map<String,Object> map=new HashMap<>();
        try {
            PageHelper.startPage(pageNum,pageSize);
            List<Complaint> complaintList=complaintService.complaintFindAll(status, compluser, responuser);
            PageInfo<Complaint>pageInfo=new PageInfo<>(complaintList);
            map.put("pageInfo",pageInfo);
            map.put("complaintList",complaintList);
            map.put("result",true);
        } catch (Exception e) {
            map.put("result",false);
            e.printStackTrace();
        }
        return map;
    }


    @ResponseBody
    @RequestMapping("updateAudit")
    public Map<String,Object> updateComplaint(Complaint complaint){
        Map<String,Object> map=new HashMap<>();
        try {
            complaintService.complaintUpdate(complaint);
            map.put("result",true);
        } catch (Exception e) {
            map.put("result",false);
            e.printStackTrace();
        }
        return map;
    }

}
